package local.bbs.cont.controller;

import local.bbs.common.controller.BaseController;
import local.bbs.common.util.PagingUtil;
import local.bbs.cont.command.BBSCommand;
import local.bbs.cont.service.BBSListService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


@Controller
@Scope("prototype")
public class BBSListController extends BaseController {
	
	@Autowired
	BBSListService bbsListService;
	
	@RequestMapping("/cont/{bbsNo}/list.do")
	public ModelAndView list(@PathVariable int bbsNo, BBSCommand bbsCommand) {
		bbsCommand.setBbsNo(bbsNo);
		ModelAndView mav = new ModelAndView();
		mav.addObject("bbsList", bbsListService.list(bbsCommand));
		mav.addObject("paging", PagingUtil.getPaging(bbsCommand));
		mav.addObject("bbsCommand", bbsCommand);
		
		return mav;
	}
	
	@RequestMapping("/cont/{bbsNo}/view.do")
	public ModelAndView view(@PathVariable int bbsNo, BBSCommand bbsCommand) {
		bbsCommand.setBbsNo(bbsNo);
		ModelAndView mav = new ModelAndView();
		mav.addObject("bbsView", bbsListService.view(bbsCommand));
		mav.addObject("bbsList", bbsListService.list(bbsCommand));
		mav.addObject("paging", PagingUtil.getPaging(bbsCommand));
		mav.addObject("bbsCommand", bbsCommand);
		
		return mav;
	}
	
}
